package org.goyo.main.domain.dao.storage.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.goyo.common.exception.DBException;
import org.goyo.common.utils.Pager;
import org.goyo.main.domain.dao.BaseDAO;
import org.goyo.main.domain.dao.storage.IInventoryUnpackDao;
import org.goyo.main.domain.entity.storage.InventoryUnpack;
import org.goyo.main.domain.entity.storage.InventoryUnpackEntry;
import org.springframework.stereotype.Repository;
@Repository
public class InventoryUnpackDaoImpl extends BaseDAO implements IInventoryUnpackDao{

	@Override
	public Pager findByCond(String cond, Pager pager) throws DBException {
		StringBuffer buf = new StringBuffer("from InventoryUnpack where 1=1 ");
		if (StringUtils.isNotBlank(cond)) {
		  buf.append(" and ");
          buf.append(cond);
		}
	    String hql = this.addSort(buf, pager);
	    String countHql = "select count(*) "+buf.toString();
		return this.findObjectsByPager(hql,countHql, pager);
	}

	@Override
	public List<InventoryUnpackEntry> findByParentId(String parentId) throws DBException {
		String hql = "from InventoryUnpackEntry where parentId=?";
		return this.findObjects(hql, null, new Object[]{parentId});
	}

}
